package com.imooc.servlet;

import com.imooc.service.MaintainService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 批量删除控制层
 */
public class DeleteBatchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置编码
        request.setCharacterEncoding("utf-8");
        // 接收页面的值
        String[] ids = request.getParameterValues("id");

        for (String id: ids) {
            System.out.print(id);
        }
        // 批量删除
        MaintainService maintainService = new MaintainService();
        maintainService.deleteBatch(ids);
        // 向页面跳转
        //request.getRequestDispatcher("/List.action").forward(request,response);
        // 重定向
        response.sendRedirect("/List.action");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
